/** @type {import('tailwindcss').Config} */
const defaultTheme = require('tailwindcss/defaultTheme')
import distance from "./src/static/distance.json"
import color from "./src/static/color.json"




// 转换像素单位
const unit = 'px,em,rem,ex,ch,pt,%,vw,vh,pt,mm,cm,in,pc,cap'
const transformKeys = (obj) => {
  let obj2 = {}
  for (let key in obj) {
    let str = obj[key].replace(/\d*/, '')
    if (str && unit.includes(str)) {
      obj2[key] = obj[key]
    } else {
      obj2[key] = obj[key] + 'px'
    }
  }
  return obj2
}

const distanceObject = transformKeys(distance)


// 转换颜色
const colorArr = color
const colorFunc = (theme) => {
  let obj = { ...theme('colors') }
  for (const key in colorArr) {
    if (colorArr[key] && typeof colorArr[key] == 'object') {
      for (const colorKey in colorArr[key]) {
        obj[key + '-' + colorKey] = colorArr[key][colorKey]
      }
    }
  }
  return obj
}







export default {
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    textColor: (theme) => {
      return colorFunc(theme)
    },
    borderColor: (theme) => {
      return colorFunc(theme)
    },
    backgroundColor: (theme) => {
      return colorFunc(theme)
    },

    extend: {
      spacing: {
        ...defaultTheme.spacing,
        ...distanceObject
      }
    },
  },
  plugins: [],
}

